package com.whfc.ms.api.safety.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.safety.service.MsSafetyAreaService;
import com.whfc.safety.dto.SafetyAreaDTO;
import com.whfc.safety.param.SafetyAreaAddParam;
import com.whfc.safety.param.SafetyAreaEditParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 责任区域
 * @Author hw
 * @Date 2021-08-19 18:11
 * @Version 1.0
 */
@RestController
@RequestMapping("/ms/api/safety/area")
public class SafetyAreaController extends BaseController {

    @Autowired
    private MsSafetyAreaService msSafetyAreaService;


    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "name", required = false) String name,
                       @RequestParam(value = "keyword", required = false) String keyword) {
        logger.info("责任区域列表,loginer:{},deptId:{},name:{},keyword:{}",
                user.getUsername(), deptId, name, keyword);
        ListData<SafetyAreaDTO> list = msSafetyAreaService.list(deptId, name, keyword);
        return ResultUtil.success(list);
    }


    @PostMapping("del/{areaId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("areaId") Integer areaId) {
        logger.info("删除责任区域,loginer:{},areaId:{}", user.getUsername(), areaId);
        msSafetyAreaService.del(areaId);
        return ResultUtil.success();
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestBody @Validated SafetyAreaAddParam param) {
        logger.info("新增责任区域,loginer:{},param:{}", user.getUsername(), param);
        msSafetyAreaService.add(param);
        return ResultUtil.success();
    }


    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestBody @Validated SafetyAreaEditParam param) {
        logger.info("修改责任区域,loginer:{},param:{}", user.getUsername(), param);
        msSafetyAreaService.edit(param);
        return ResultUtil.success();
    }

}
